import {localRead} from '@/libs/util'

export default {
    inserted: function (el, binding, vnode) {

        // el.lastChild.innerHTML 查询
        let btnPer = binding.value
        let has = false;
        // 当前路由
        let currentMenu = vnode.context.$route
        if (currentMenu.meta.access !== undefined) {
            has = currentMenu.meta.access.indexOf(btnPer) >= 0
        }
        if (!has) {
            el.parentNode.removeChild(el);
        }
        // // 获取本地菜单信息
        // let list = JSON.parse(localRead('dynamicRouter'))
        // // 存在则返回index>0
        // let hasPermission = has(binding.value, list)
        // if (!hasPermission) {
        //     el.parentNode.removeChild(el);
        // }
    }
}

export const has=(value, list)=> {
    let index = list.filter((item, i) => {
        if (item.meta.access !== undefined) {
            if (item.meta.access.indexOf(value) >= 0) {
                return true;
            }
        }
        if (item.children) {
            has(value, item.children)
        }
    })
    let result = false;
    if (index.length > 0) {
        result = true;
    }
    return result
}